package com.strive.demo.web.filter;

import com.strive.common.model.base.RequestModel;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.UUID;

/**
 * @description:
 * @author: bingcun.chen
 * @Date: 2022/3/10 16:21
 * @Version 1.0
 */
public class WebCorsFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletResponse res = (HttpServletResponse)servletResponse;
        res.setHeader("Access-Control-Allow-Origin","*");
        res.setHeader("Access-Control-Allow-Methods","*");
        res.setHeader("Access-Control-Allow-Headers", " Origin, X-Requested-With, Content-Type, Accept");

        RequestModel requestModel = new RequestModel();
        requestModel.setRequestId(UUID.randomUUID().toString().replace("-",""));
        RequestModel.setRequestModel(requestModel);
        filterChain.doFilter(servletRequest,servletResponse);
    }
}
